﻿@model STX.Admin.Models.BizQuotePriceTemplate.AddModel
@{
    ViewBag.Title = "Add";
    Layout = null;
}

<form class="pageForm addpage" action="@Url.Action("saveadd")" method="post" id="addBizQuotePriceTemplate">
    <div style=" height:100%; width:100%; overflow:hidden" class="verticalSplitContainer">
        <div class="pageFormContent" ratio="*">

            <table style="width:100%">
                <tr>
                    <td>地区：</td>
                    <td>
                        @Html.DropDownList("AreaId", Model.Areas)
                    </td>
                    <td>是否拆分：</td>
                    <td>@(Html.DropDownListFromEnum<STX.Domain.BizQuotePriceTemplate.SplitEnum>(0, "Split")) (制作成本时)</td>
                </tr> 
                <tr>    
                    <td width="15%">选择物料分类：</td>
                    <td width="35%">@Html.DropDownList("MaterialCategoryId", Model.MaterialCategories)</td>
                    <td width="15%">编号：</td>
                    <td width="35%"> <input name="Code" class="textInput" type="text" size="10" value="" alt=""/> <span style="color: #ff0000"></span> 编号须唯一
                    </td>
                </tr>
                <tr>
                    <td>名称：</td>
                    <td><input name="Name" class="textInput" type="text" size="30" value="" alt=""/></td>
                    <td>单位：</td>
                    <td><input name="Unit" class="textInput" type="text" size="10" value="" alt=""/></td>
                </tr>  
                <tr>
                    <td>项目成本价：</td>
                    <td><input name="ProjectCostPrice" class="textInput" type="text" size="10" value="" alt=""/></td>
                    <td>财务成本价：</td>
                    <td><input name="FinanceCostPrice" class="textInput" type="text" size="10" value="" alt=""/></td>
                </tr>  
                <tr>
                    <td>具体要求：</td>
                    <td colspan="3">
                        <input name="Required" class="textInput" type="text" size="100" value="" alt=""/>
                    </td>
                </tr> 
            </table>
            <br/>
            <h4 style=" background: #b0e0e6; padding: 6px;">价格详细（填写数量时 保证所填写数量合乎逻辑）</h4>
            <table style="width:100%" id="tablepricelsit">
                <tr>
                    <td width="40%">数量</td>
                    <td width="60%">对外报价</td>
                </tr>
                <tr>
                    <td><input name="BizQuotePrices[0].StartNum" class="textInput" type="text" size="15" value="0" alt=""/>&nbsp;至&nbsp;<input name="BizQuotePrices[0].EndNum" class="textInput" type="text" size="15" value="0" alt=""/></td>
                    <td><input name="BizQuotePrices[0].QuotePrice" class="textInput" type="text" size="15" value="0" alt=""/> </td>
                </tr>
            </table>
            <br/>
            <a href="javascript:;" title="添加一行" id="addtr">+ 添加一行</a> &nbsp;&nbsp;&nbsp;&nbsp; <a href="javascript:;" title="删去一行" id="removetr">- 删去一行</a>
        </div>

        <div class="formBar" ratio="#30">
            <ul>
                <div class="simplebutton"><div class="r"><button type="button" class="submit">保存</button></div></div>
            </ul>
        </div>
    </div>
    <script type="text/javascript">
        $(function () {

            function AddOrRemoveCallback() {
                $("#tablepricelsit tr:not(:first)").each(function (i) {
                    $(this).find("input").each(function () {
                        var $thisinput = $(this);
                        $thisinput.attr("name", $thisinput.attr("name").replace(/\d+/g, i));
                    });
                });
            }

            $("#addtr").click(function () {
                var $tr = $("#tablepricelsit tr:last").clone();
                $tr.appendTo($("#tablepricelsit"));
                AddOrRemoveCallback();
            });
            $("#removetr").click(function () {
                if ($("#tablepricelsit tr").size() > 2) {
                    $("#tablepricelsit tr:last").remove();
                    AddOrRemoveCallback();
                }
            });

            $("#addBizQuotePriceTemplate [name='Code']").keyup(function () {
                var $this = $(this);
                var val = $this.val();
                if (!val) {
                    return;
                }
                var data = { code: val };
                var option = {
                    url: "@Url.Action("CheckIsExistCode")",
                    data: data,
                    type: "POST",
                    dataType: "json",
                    success: function(json) {
                        if (json.success) {
                            if (json.msg) {
                                $this.next().text(json.msg);
                            } else {
                                $this.next().text("");
                            }
                        }
                    }
                };
                $.ajax(option);
                
            });

        });
</script>
</form>
